package com.service.admin.product.controller;

import java.util.Arrays;
import java.util.Map;

import com.service.admin.product.controller.req.CategoryPageReq;
import com.service.admin.product.service.ProductCategoryService;
import com.service.core.rest.BaseController;
import com.service.core.rest.response.BaseResponse;
import com.service.core.rest.response.MultiResponse;
import com.service.core.rest.response.OneResponse;
import com.service.core.rest.response.PageResponse;
import com.service.dao.model.ProductCategory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * 商品分类
 *
 * @author xxxx
 * @email xxxx@qq.com
 * @date 2020-04-28 10:56:56
 */
@RestController
@RequestMapping("product-category")
public class ProductCategoryController extends BaseController {
    @Autowired
    private ProductCategoryService productCategoryService;

    /**
     * 商品分类
     * 列表
     *
     * @author xxxx
     * @email xxxx@qq.com
     * @date 2020-04-28 10:56:56
     */
    @PostMapping("/page")
    public PageResponse<?> query(@RequestBody CategoryPageReq categoryPageReq) {
        return successQueryPageResponse(productCategoryService.page(categoryPageReq));
    }

    /**
     * 商品list all
     * 列表
     *
     * @author xxxx
     * @email xxxx@qq.com
     * @date 2020-04-28 10:56:56
     */
    @PostMapping("/list-all")
    public MultiResponse<?> listAllByLanguage(@RequestBody CategoryPageReq categoryPageReq) {
        return successQueryMultiResponse(productCategoryService.listAll(categoryPageReq));
    }

    /**
     * 商品分类
     * 信息
     *
     * @author xxxx
     * @email xxxx@qq.com
     * @date 2020-04-28 10:56:56
     */
    @GetMapping("detail/{id}")
    public OneResponse<?> load(@PathVariable("id") Integer id) {
        return successQueryOneResponse(productCategoryService.getById(id));
    }

    /**
     * 商品分类
     * 保存
     *
     * @author xxxx
     * @email xxxx@qq.com
     * @date 2020-04-28 10:56:56
     */
    @PostMapping("/create")
    public BaseResponse create(@RequestBody ProductCategory productCategory) {
        productCategoryService.save(productCategory);
        return successBaseResponse();
    }

    /**
     * 商品分类
     * 修改
     *
     * @author xxxx
     * @email xxxx@qq.com
     * @date 2020-04-28 10:56:56
     */
    @RequestMapping("/update")
    public BaseResponse update(@RequestBody ProductCategory productCategory) {
        productCategoryService.updateById(productCategory);
        return successBaseResponse();
    }

    /**
     * 商品分类
     * 删除
     *
     * @author xxxx
     * @email xxxx@qq.com
     * @date 2020-04-28 10:56:56
     */
    @RequestMapping("/remove")
    public BaseResponse remove(@RequestBody Integer[] ids) {
        productCategoryService.removeByIds(Arrays.asList(ids));
        return successBaseResponse();
    }
}
